package com.mezz.bones.framework.mybatis.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.mezz.bones.framework.core.helper.SnowflakeIdGeneratorHelper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author mezz
 * @date 2022-04-17 12:27
 * @description:
 */
@Configuration
@MapperScan("com.mezz.bones.**.mapper")
public class MybatisPlusConfig {


    @Value("${spring.profiles.active:default}")
    private String activeProfile;

  /**
   * description: 分页插件
   * <p>
   * * @Date 2021/8/10 下午2:28
   */
    /**
     * 添加分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 如果配置多个插件, 切记分页最后添加
        // 如果有多数据源可以不配具体类型, 否则都建议配上具体的 DbType
        return interceptor;
    }

    @Bean
    public IdentifierGenerator identifierGenerator(SnowflakeIdGeneratorHelper snowflakeIdGeneratorHelper) {
        return (entity) -> snowflakeIdGeneratorHelper.nextId();
    }

}
